﻿namespace CoCoonCoreWM6
{
    public static class RAM
    {
        //#region singleton instantiation

        //static readonly RAM instance = new RAM();
        //public static RAM Instance
        //{
        //    get
        //    {
        //        return instance;
        //    }
        //}

        //#endregion

        public static byte[] Memory { get; set; }

        public static void Initialize(int size)
        {
            Memory = new byte[size];
            for (int i = 0; i < Memory.Length; i++)
            {
                Memory[i] = 0;//170 204 240
            }
        }

        public static void TestProgram()
        {
            Memory[0] = 0x8E;
            Memory[1] = 0x04;
            Memory[2] = 0x00;

            Memory[3] = 0xB6;
            Memory[4] = 0x00;
            Memory[5] = 0x28;

            Memory[6] = 0xA7;
            Memory[7] = 0x81;
            
            Memory[8] = 0x8C;
            Memory[9] = 0x1B;
            Memory[10] = 0xFF;

            Memory[11] = 0x23;
            Memory[12] = 0xF9;
            
            Memory[13] = 0x12;

            Memory[14] = 0x10;
            Memory[15] = 0x8E;
            Memory[16] = 0x15;
            Memory[17] = 0xFF;

            Memory[14] = 0x20;
            Memory[15] = 0xFD;

            Memory[18] = 0x31;
            Memory[19] = 0x3F;

            Memory[20] = 0xC6;
            Memory[21] = 0xFF;

            Memory[22] = 0x5A;

            Memory[23] = 0x12;

            Memory[24] = 0x26;
            Memory[25] = 0xFB;

            Memory[26] = 0x10;
            Memory[27] = 0x8C;
            Memory[28] = 0x00;
            Memory[29] = 0x00;

            Memory[30] = 0x26;
            Memory[31] = 0xF1;

            Memory[32] = 0x7A;
            Memory[33] = 0x00;
            Memory[34] = 0x28;

            Memory[35] = 0x20;
            Memory[36] = 0xDE;
            
            Memory[37] = 0x20;
            Memory[38] = 0xFD;

            Memory[39] = 0x12;

            Memory[40] = 0xFF;


        }
    }
}

/*
Sample code

        ORG     $0000      * 
START   LDX     #VIDRAM    * 8E 04 00       * point to screen start
        LDA     #PATRN     * B6 00 28       * load bit pattern 
DRAWP   STA     ,X+        * A7 81          * draw bits on screen 
        CMPX    #$1BFF     * 8C 1B FF       * check for end
        BLS     DRAWP      * 23 F9          * loop until done (-7) 
LOOP1   NOP                * 12             * do nothing 
        BRA     LOOP1      * 20 FD          * loop like forever (-3)
DELAY   LDY     #$15FF     * 10 8E 15 FF    * load counter repeat 
REPEAT  LEAY    -1,Y       * 31 3F          * decrement repeat
        LDB     #$FF       * C6 FF          * load counter start
CNTDWN  DECB               * 5A             * decrement counter
        NOP                * 12             * do nothing
        BNE     CNTDWN     * 26 FB          * loop until zero
        CMPY    #$0000     * 10 8C 00 00    * repeat again? 
        BNE     #REPEAT    * 26 F1          * loop until zero
        DEC     #PATRN     * 7A 00 28       * change draw pattern (decrement)
        BRA     DRAWP      * 20 DE          * draw again
LOOP2   NOP                * 12             * do nothing 
        BRA     LOOP2      * 20 FD          * loop like forever (-3) 
PATRN   FCB     #FF        * FF 
        END 

        
 

*/